<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\goods\Order;
use app\common\controller\Api;
use app\common\controller\Payment;
use think\Controller;
use think\Db;
use think\Request;


class Userblacks extends Api
{
    private static $model;
//    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new \app\common\model\UserBlacks();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function lists()
    {
        $where = [
            'status' => 1
        ];

        $list = self::$model->where($where)->order('sort asc')->select();
        $this->success('我的预约', $list);
    }

    /*
     * 加入黑名单
     */
    public function create()
    {
        $touserId = input('touser_id');
        if (!$touserId) {
            $this->error('参数缺失！');
        }
        $userId = $this->auth->id;
        $where = [
            'user_id' => $userId,
            'touser_id' => $touserId,
        ];

        $row_info = self::$model->where($where)->find();
        if ($row_info) {
            $this->error('该会员已加入黑名单！');
        }

        $res = self::$model->create($where);
        if (!$res->id) {
            $this->error('加入失败！');
        }
        $this->success('加入成功！');
    }

    /**
     * 移除黑名单
     */
    public function del()
    {
        $touserId = input('touser_id');
        if (!$touserId) {
            $this->error('参数缺失！');
        }
        $userId = $this->auth->id;
        $where = [
            'user_id' => $userId,
            'touser_id' => $touserId,
        ];

        $row_info = self::$model->where($where)->find();
        if (!$row_info) {
            $this->error('该会员尚未加入黑名单！');
        }

        $res = self::$model->where('id', $row_info->id)->delete();
        if (!$res) {
            $this->error('移除失败！');
        }
        $this->success('移除成功！');
    }
}
